#抓取海报
import requests

url1 = 'https://api.douban.com/v2/movie/1292052?apikey=0df993c66c0c636e29ecbb5344252a4a'
inf = requests.get(url1,headers={'user-agent':'chrome'})
#print(inf.text)

dic_inf = inf.json()
#print(dic_inf)
url_image = dic_inf.get('image')
#print(url_image)
image = requests.get(url_image,headers={'user-agent':'chrome'})
#print(image.content)

with open('爬虫\\xiaoshenke.jpg','wb') as f:
    f.write(image.content)

start = 0
top250_movie = []

while start < 40:
    
    try:
        url = 'https://api.douban.com/v2/movie/top250?start=' + str(start) + '&apikey=0df993c66c0c636e29ecbb5344252a4a'
        total_info = requests.get(url,headers={'user-agent':'chrome'})
        #print(dic_movie)
                
    except:
        print('获取失败')
    start += 20
    dic_url = total_info.json()    
    list_movie = dic_url.get('subjects')
    for movie in list_movie:                                                                                                                                                                                                                                                                                                                                                                  
        #print(movie)
        title_movie = movie['title']     
        image_movie = movie['images']['small']
        #print(image_movie)
        poster = requests.get(image_movie,headers={'user-agent':'chrome'})
        
        with open('爬虫\\{}.jpg'.format(title_movie),'wb') as f1:
            f1.write(poster.content)
        
        
